Okay, so in today's lesson we are going to have a look at the second use of attachments.
And I think this use of attachments is probably the more major use.
And this is to do with constraints okay.
So there are lots of different types of constraint.
And they they vary from um, most of them are to do interactions between two parts.
So how two parts interact.
Um, but they range from things like rope and strings to things like hinges and ball and socket constraints.
So lots of stuff to have a look at here.
So um, to start off with, we're going to go over to model.
And over here you can see you have the um constraints area here.
Now we're not going to particularly use this too much, but you can see here a nice list of all the
different constraints.
Okay.
So so um, rigid constraint ball and socket hinge prismatic cylindrical and so on.
Okay.
We're going to look through most of these.
But I might skip a couple out um, either because I don't think they're that useful or they're a bit
too advanced for this scope.
Okay.
Um, the ones down here, um, I'm not going to be covering in this lesson as, um, I think they're
more to do with forces rather than, um, physics and interactions and stuff.
So we're not going to cover them just yet.
Okay.
So let's start off by adding two parts into the workspace okay.
So one parts here and one part here.
Okay.
So the first constraint I want to show you is the ball in socket constraint.
Ball in socket constraint.
And this does is what you would imagine okay.
Ball and socket is a type of joint you have between bones in your body.
Um a good example is your shoulder or I guess your like your chest and your arm, the way you can move
your arm around in a circle.
You're probably doing it now, like me, but where you're moving around your arm in a circle, that's
a ball and socket constraint okay.
Whereas other joints in your body, such as your lower arm and your upper arm, don't go around in that
circle.
You can't move your lower arm around in a circle, but you can your upper arm.
That's because your upper arm uses a ball and socket, a ball and socket joint.
But we're going to apply that to roadblock by looking at ball and sockets.
Um, ball and socket constraints instead.
Um, so for this one I'm going to have one part up here and one part here, and I'm just going to rotate
it like that and move it up just like that.
So it touches like that there.
Okay.
Um, now with these constraints, um, usually you want one part to be anchored and the other part to
be unanchored.
So this part here is going to be moving, whereas this part here is going to be staying.
Staying um, staying the same position as um of any kind of constraints.
Usually one part is moving and you have a part is kind of um, is where it starts or where it's kind
of held from.
So we don't want this one to move.
So we want anchor to be on which it is.
And this one here, make sure it's on anchored.
Okay.
Cool.
Now to work on creating the constraints.
So add a attachment into both of these.
I'm going to call this one attachment zero and add one into here.
And.
Attachment one.
I'm going to move these over.
Touching just at where they where both of them collide.
So this one moves down to about here.
And this one moves up to there as well.
So both of the attachments are in the same location okay.
You want now if you want that with most of your constraints such as most of the interaction based constraints
like ball and sockets, you want them connected together okay.
So let's go ahead and play the game and see how this works okay a lot of these is easier to explain
it.
So it's easier to show you it rather than explain it to you.
And it hasn't seen of course I haven't set it up yet.
Sorry about that.
Um, right into this part you need to obviously add in a ball and socket constraints.
I didn't even set up properly.
No, undo didn't work.
And this is the constraint here.
The constraints are objects that you add in similar to be part effects.
We looked at.
We looked at last lesson you need to put in here, whether it's which one which attachment is going
to be attachment zero and which attachment is going to be attachment one.
Set about over there and put that over there.
Just like how we're done before.
And now we have.
You can now.
Now you can see we've actually got a ball and socket there.
You can see.
Okay.
Um, so let's play the game and see how this works.
Okay.
Load into the game and you can see how it interacts with the object.
So it's able to move around like that very freely as I hit it and move it around like that.
Now not very realistic.
Okay.
Um, which is fine because we can put limits onto these constraints.
So you have some appearance properties up here which are just to do the basic appearance and nothing
too difficult there.
Um, but the limits enabled is quite important.
You can put certain limits on your constraints, basically prevent them from doing too much work.
As we saw there, they were rotating like crazy, like crazy.
So we don't need that.
Okay.
So turning limits enabled on it gives us free limits.
It gives us restitution, twist limits enabled and upper angle restitution basically means how elastic
it is.
So how much it's able to stretch and bend and things like that value from 0 to 1.
Um, twist limits enabled is a very important one as well.
You can put further limits on for the amount of rotates, which is probably what we're going to be looking
at mostly there and upper angle as well of 45.
So this means it's able to rotate 45 degrees.
So up to about here before it stops.
I think personally that's pretty good.
So let's play the game and see what it looks like now with these um, with these limits on.
Okay.
You can see here for some reason it's starts stopping there.
Um, not too sure why it's doing that.
Let's have a look as to why that might be.
Um.
Lower angle.
Upper angle.
It could be that we need to rotate it.
As you can see here, this cone here is where it can be rotated.
So properly we need to rotate some of the attachments.
So we rotate this 45 degrees.
Let's check it out now.
Um oh not quite.
Let's try and rotate attachment zero.
There we go.
So now you can see the cone is pointed downwards.
And that cone basically represents the area that it can be rotated.
Um so let's try again.
And oh, it still hasn't worked.
Okay.
You know, you can see it is working a little bit better.
You can spin it around like that and they are a bit difficult to show, I think.
Um, let's see what other ones we could change.
Um, if we turn, um.
So the upper angle of 45.
Let's change this to 90.
And changes to -90 and 90 like that there.
I think it might work a little bit better.
There we go.
Only see here.
It stops once it goes upwards like that.
There.
So some of these constraints sometimes are a little bit buggy.
As you can see they're not perfect.
But it does work quite well for certain things.
Um this one why you might want to use this.
Um, well, sometimes you have, um.
Let's say, like, um.
Like, maybe you have chains coming down and you want to be able to.
You want you want your player to be able to walk through the chains.
You could do something like that with this here.
So there are just kind of small uses with these, but that they can really, um, make your game much
more realistic as you're adding, um, instead of just walking through them and, and not doing anything,
they're actually reacting to the player walking through.
So these kind of constraints, even though they're very small adjustments you can make to your game,
they make it much more lifelike.
So when there is a possibility to use a constraint, even though it can be a bit difficult to set up,
I'd highly recommend doing it.
Okay, so that's the first one the ball and socket.
I'm going to delete that.
I'm going to talk about the next type which let's look at hinge next.
So hinge is for doors okay.
So that allows a um.
The object to rotate freely along one axis.
So for this we need to set up slightly differently.
So I'm going to select both of these and add some more parts in.
So my first part is going to be just here.
It's up there.
And my second one is going to be across.
Like fat there.
Okay.
And I'm going to add in well with doors we wanted to make a door.
The best way to highlight this hinge constraint is to use two, because with doors you have a hinge
at the top and the bottom.
So that's what I'm going to set up in this case.
Or maybe we can try it first and see see what it's like.
And if we don't like it we can always change it to be two.
Okay.
We have these two constraints here.
Sorry.
These two attachments here.
Let's move them into place.
So they're and they're quite nice.
And you can see how it's very important for, for these constraints to use attachments because it needs
to be the specific areas of these parts which are being affected.
So it is very important that we're using attachments in this case.
Okay.
Let's not make my mistake I made last time and add in the actual constraint.
So the hinge constraint in this case select your two attachments like that's they're typically um it
does matter a bit more now which attachment attachments you'll be putting to each one.
Attachment zero isn't supposed to move.
And attachment one is attached to the part that is supposed to move.
So in this case we write to put attachment one to this larger part.
Because I'm wanting this one to move okay.
We're going to put no no limits enabled for now.
And we're going to see how this works.
So let's push this.
Oh, have I anchored it?
I might have, I have.
Let's anchor that and try that again.
Push it.
Oh, I can see it moving slightly, but not quite.
I think it might be the thickness of these parts, so if I decrease the thickness slightly and try again.
Okay.
It's wanting to, um.
Let's try, um, let's try this with two of them.
It's got a feeling that, um.
It's because we're only using.
Only using?
Um, yeah.
I got a feeling because it's we use only using one.
So two attachment we're using at the bottom add in a hinge constraint.
And this one is one we haven't set up yet.
That's one zero.
Attachment one.
Let's try again.
All right.
Um, what might be going on here?
Both enabled, um, limits enabled on.
Um.
Okay, let's try and do it this way.
Um, it's always great when things don't work.
Um, select these to push them down.
My idea is that it might be doing it along the wrong axis, which is why I've done it this way.
What axis is it wanting to do it on then?
Mm.
He's the weird one.
Um.
Let's delete.
Those and just go with one set of attachments.
Here.
Um.
Oh, there we go.
Got it working.
Okay, so we can see how this hinge constraint works.
It's hinging it at that point so it can freely rotate.
Okay.
Now I probably shouldn't.
Probably my fault there for jumping into an example showing a door because doors are quite complex when
it comes to physics.
Um, so we wouldn't.
So it might be a bit more difficult to do one of those just yet.
As an example, you can see it spins around.
It's quite cool.
Maybe sometimes you have, um.
Wind dials, for example, could be an example of what you could use for this, or like a revolving
door as well.
So some really cool examples that you can use for this.
Um, I believe we're using this one.
Let's look at some of the limits then.
So let's turn limits enabled on.
And let's now change the limits between a 45 degree, um upper angle and lower angle, which means it
can only rotate 45 degrees each way.
You see how this affects it?
Um, it only it stops rotating at that point.
Not really good for what we want to do.
So I'm going to change this to -90.
So it does a quarter turn before it stops.
Now I think that's a really good way to do that.
Persia.
We can go in quite nicely like that there and close it back up afterwards.
So pretty cool.
Okay.
Um, okay.
We also have a property here called actuator type.
Now actuator types are quite advanced.
I'm going to touch on to them just so you're aware of them.
Basically there are two um actuator types motor and serve and servo.
So basically they work different ways.
So um based on the rotation and the limits of the rotation.
So I'm going to put put them to be both ways and show you how they work.
So motor I've put zero zero and infinite is the default.
Let's try this and see how it works.
So this is using the motor actuator type.
And we can see it opens up quite quickly like that there.
Okay, um, let's try the servo type.
They're not moving.
It's not moving.
Interesting, so you can easily see it as a difference between the two.
Angular speed let's say ten and max torque ten.
Is.
Um.
Target angle 90 degrees.
Maybe because I didn't put one in there.
Um, there are lots of properties when it comes to constraints, and I.
There we go.
It's working just like that.
So basically the difference between the two is that the motor actuator type puts limits based on the
force that's applied.
So motor here you can see you have the angular velocity that's occurring.
So that's the velocity is basically its speed.
But with a given direction.
This is probably all quite confusing and might be a bit too advanced for some people I guess.
But again this is the advanced section.
Um, but you can see here it's um, much faster.
I'm not putting too much pressure on.
It's going quite a lot.
That's because I've set up the, um, angular velocity to ten motor.
Max torque is the maximum amount of torque you can put into the maximum speed almost, and the max acceleration
is infinite in this case, um, whereas the servo has it more based on rotations.
So the angular speed, the angular response and things like that.
Again, I think, um, unless you're making something very, very advanced, you don't need to necessarily
know about all these little bits.
It's good.
Just a small introduction, but definitely, um, you know, do some more research and have a look a
bit more at these things.
We've quite a lot to go through.
Um, but it's just a starter.
On the differences between motor and servo.
Um, I haven't really used actuator types that much personally in my games.
Um, I mean, you don't necessarily use constraints too much, so perchance you then go ahead and use
actuator type is quite low, but I guess it is still worth knowing, especially if you find this interesting
and you understand some of the terms such as torque and things like that.
Like.
And done.
The next two I want to show you have a very similar setup.
Um, so these are the prismatic and cylindrical constraints.
So these two, if I add a part into the game um, as always, and scale it up, these work between two
parts.
So one part here.
One part here and one part in the middle.
So this is basically this part going between each of these two parts here.
So this part here, let's add in um two attachments.
Attachment one because these are the ones that are going to be moving okay.
So one is going to be on the left side and one is going to be all we need to change that probably to
be to five.
Um yep.
Nice.
And then this side cool.
These are both be called attachment one.
Okay.
And in this side we want a another attachment.
Call this attachment zero.
Move that just to the edge and in this side as well.
Add in an attachment zero.
And put that outside as well.
We're going to be using the one at the bottom.
So let's go over to here.
Add in a um prismatic constraint.
Start off with and attachment zero is here.
And attachment one is the one we're choosing at the bottom because they both have the same name okay.
And then you can see it's joining those two together like that's there.
Same for the other side.
Let's add in a prismatic constraint.
And you do need two of these in order for this to properly work.
Attachment zero.
Attachment one.
Make sure we're set up correctly.
Yep.
So you can see the first one there and the second one there.
Okay let's play this and see how this works.
So this is going to go between the two parts.
And it basically allows you to um.
Okay.
Probably anchored it.
Need to stop forgetting to anchor this stuff.
Um.
So try again.
There we go.
See it go in between those two parts like that.
So it's going left to right.
And we can push it like that.
And it basically will bounce off the other two parts just like that.
So pretty cool for you to use.
Um, a use of this one.
Um.
Not too sure.
Um, obviously you'd probably want you wouldn't want it particularly use it with a floating part in
this case.
Um hum.
Something that kind of moves based on an axis.
Maybe you can push pushing something up an axis or something like that.
Um, there are uses for these, but again, you are going to use some a lot more than others.
So it just goes between those two parts and bounces off them just like that.
Really.
Okay.
Um, the properties of these ones are very similar.
You have two different actuator types.
You have the limits enabled, and the limits is basically just the speed.
So a lower limit of zero and upper limit of five.
So I'm not going to talk too much about those now um just some of the basics with those.
Okay.
And um the other type is the cylindrical constraint which I'm going to set up as well.
So cylindrical constraint.
Let's attach that to here.
And it is the bottom one we want to connect this one to just so they're on the right.
Oh no.
Top one just to make sure they're on the right side.
And this one here.
Attachment zero to there.
And attachment one to there.
Cool.
Okay, now we cylindrical works much the same, but it rotates as it moves.
So this one here can rotate around as it moves, which is pretty cool.
Okay.
Um, now the properties of this one, let's select both of these same kind of stuff.
Only difference is that in this case there are some angular limits you can turn on as well.
So the lower angle the upper angle just things like that okay.
So there are first few constraints.
I'm going to split this up into two lessons.
So the second lesson, we're going to have a look at the other types of constraint as well.
So I hope you've enjoyed looking at the first first couple and already got some cool uses for them in
your head.
And we're going to have a look at the other ones in the next lecture.